$(document).ready(function(){
	initdept();
});
function setdept(deptid,deptname){
	JsGetLoginInfo.setCurrDept(deptid,deptname,function(data){
			initdept();
	});
}
function initdept(){
	JsGetLoginInfo.getUserInfo(function(data){
		$("#usernamediv").html(data.username);
		$("#deptnamediv").html("<span id='deptdivid'>["+data.deptname+"]</span>");
		var deptlist = data.deptlist;
		if(deptlist!=null&&deptlist.length){
			$("#deptdivid").click(function(){
				var htmlt="";
				htmlt="<select id='deptselect' onchange='setdept(this.value,$(\"#deptselect option:selected\").text())'>";
				for(var i=0;i<deptlist.length;i++){
					if(data.deptid==deptlist[i].deptid){
						htmlt+="<option selected value='"+deptlist[i].deptid+"'>"
					}else{
						htmlt+="<option value='"+deptlist[i].deptid+"'>"
					}
					htmlt+=deptlist[i].dept;
					htmlt+="</option>"
				}
				htmlt+="</select>"
				$("#deptnamediv").html(htmlt);
				$("#deptselect").focus();
				$("#deptselect").blur(function(){
					initdept();
				});
			});
				
		}
	});
}